<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
<link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel="stylesheet">
<script src="${pageContext.request.contextPath}/js/jquery-1.9.1.js"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
<link href="${pageContext.request.contextPath}/themes/material/easyui.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/themes/icon.css" rel="stylesheet">
<script src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
   $(document).ready(function(){
	 //配置购物单数据表格
		$('#ginventoryinfo').datagrid({
			url : '${pageContext.request.contextPath}/selectGinventoryInfo',
			columns : [ [ {field:'checked',checkbox:true,width:100},{
				field : 'gid',
				title : '商品编号',
				width : 106,
				
			}, {
				field : 'gname',
				title : '商品名称',
				width : 106,
			}, {
				field : 'ginventory',
				title : '商品库存',
				width : 106,
				
			}, {
				field : 'gcost',
				title : '商品进价',
				width : 106,
			}, {
				field : 'sname',
				title : '供应商名称',
				width : 106,
			}, ] ],
			pagination : true,
			striped : true,
			rownumbers : true,

			
		})
		$("#addorder").click(function(){
			$("#pan").show();
			var gins = $("#ginventoryinfo").datagrid('getSelections');
		      $(gins).each(function(v,m){
				 $("#dinghuo").append("<tr><td>编号:<input readonly='readonly' style='width:40px;' type='text' name='gid' value='"+m.gid+"' /></td><td>名称:<input readonly='readonly' style='width:60px;' type='text' name='gname' value='"+m.gname+"'/></td><td>进货数:<input id='gnumber' style='width:40px;' type='text' name='gnumber' /></td><td>进价:<input readonly='readonly' style='width:40px;' type='text' name='gcost' value='"+m.gcost+"'/></td><td>供应商:<input readonly='readonly' style='width:60px;' type='text' name='sname' value='"+m.sname+"'/></td><td><button id='delete' onclick='delete1()' type='button' class='btn btn-primary btn-xs'>删除</button></td></tr>")
				 });
		})
		
		 $("#sumbitdingdhuoorder").click(function(){
	     var  dinghuoorder =  $("#dinghuodingdan").serializeArray();
	     var o ={};
	     $.each(dinghuoorder,function(index){
			  if(o[this['name']]){
			  o[this['name']] = o[this['name']] +","+this['value'];
			  }else{
			  o[this['name']] = this['value'];
			  }
			  });  
	    
	     var gnumbers=o.gnumber;
	        if(gnumbers.indexOf("-")>=0){
	           alert("不能输入负数哟!")
	        }else{
	            $.ajax({
	            	type:'post',
	            	url:'${pageContext.request.contextPath}/submitdinghuoorder',
	            	data:{"dinghuoorder":JSON.stringify(o)},
	            	dataType:'json',
	            	success:function(data){
	            	   $("#msg").text(data.msg);
	            	   $("#money").text(data.totalmoney+"元");
	            	}
	            	
	            })
	        }

	  })

	  
   })
    function delete1(){
	 
      var table=document.getElementById("delete").parentNode.parentNode.parentNode;
      var tr=document.getElementById("delete").parentNode.parentNode
      table.removeChild(tr)
	  }
</script>
</head>
<body>
<div class="container-fluid">
  <div class="row">
     <div class="col-md-7" >
       <h3 style="color: red;"> 注意：下列商品库存不足50件，急需进货！！</h3>
       <table id="ginventoryinfo"></table>
      <button id="addorder" style="margin-left: 532px" type="button" class="btn btn-success">加入订单</button>
     </div>

			<div class="col-md-5">
				<br>
				<br>
				<br>
				<div id="pan" class="panel panel-default"
					style="width:380px; margin-left: 50px; display: none;">
					<div class="panel-heading">
						<h3 class="panel-title">订货订单</h3>
					</div>
					<div class="panel-body">
						<form action="${pageContext.request.contextPath}/dayindinghuoorder" method="post" id="dinghuodingdan">
							<table id="dinghuo"
								class="table table-striped  table-bordered table-condensed">
								<tr></tr>
								
								</table>
						订单金额:<label id="money"></label><br>
						<label id="msg"></label>
						
						<button  id="sumbitdingdhuoorder" style="margin-left:250px" type="button" class="btn btn-success">加入订单</button>
						<br><br>
						<button id="daochu" style="margin-left:254px;" type="submit" class="btn btn-success">打印订单</button>
						
						</form>
					
					</div>
				</div>
			</div>

		</div>
</div>

</body>
</html>